#ifndef TCP_SERVER_HTTPRESPONSE_H
#define TCP_SERVER_HTTPRESPONSE_H

#include "../../base/copyable.h"
#include "../../base/Types.h"

#include <map>

class Buffer;

class HttpResponse : public muduo::copyable {
public:
    enum HttpStatusCode {
        kUnknown,
        k200Ok = 200,
        k301MovedPermanently = 301,
        k400BadRequest = 400,
        k404NotFound = 404,
    };

    explicit HttpResponse(bool close)
            : statusCode_(kUnknown),
              closeConnection_(close) {
    }

    void setStatusCode(HttpStatusCode code) { statusCode_ = code; }

    void setStatusMessage(const string &message) { statusMessage_ = message; }

    void setCloseConnection(bool on) { closeConnection_ = on; }

    void setContentType(const string &contentType) { addHeader("Content-Type", contentType); }

    void setBody(const string &body) { body_ = body; }

    bool closeConnection() const { return closeConnection_; }

    // FIXME: replace string with StringPiece
    void addHeader(const string &key, const string &value) { headers_[key] = value; }

    void appendToBuffer(Buffer *output) const;

private:
    std::map<string, string> headers_;
    HttpStatusCode statusCode_;
    // FIXME: add http version
    string statusMessage_;
    bool closeConnection_;
    string body_;

};

#endif //TCP_SERVER_HTTPRESPONSE_H
